<?php 
//change nhận các giá trị always,hourly,daily,weekly,Weekly,yearly,never
//prio nhận các giá trị 0.0 -> 1.0
$sitemap = '';
$sitemap .= '<url>
                <loc>'.DOMAIN.'</loc>
                <changefreq>Daily</changefreq>
                <priority>1.00</priority>
              </url>';
              
// Dien thoai
$sitemap .= '<url>';
$sitemap .= '<loc>'.DOMAIN.'/dien-thoai/'.'</loc>';
$sitemap .= '<changefreq>Weekly</changefreq>';
$sitemap .= '<priority>0.80</priority>';
$sitemap .= '</url>';
$list_catpro = db_array('SELECT cat_name,cat_alias FROM categories WHERE cat_type = "products" LIMIT 20');
foreach($list_catpro as $cat) {
   $sitemap .= '<url>';
   $sitemap .= '<loc>'.DOMAIN.'/dien-thoai-'.$cat['cat_alias'].'/'.'</loc>';
   $sitemap .= '<changefreq>Weekly</changefreq>';
   $sitemap .= '<priority>0.80</priority>';
   $sitemap .= '</url>';
}       
              
// Dich vu
$sitemap .= '<url>';
$sitemap .= '<loc>'.DOMAIN.'/dich-vu/'.'</loc>';
$sitemap .= '<changefreq>Weekly</changefreq>';
$sitemap .= '<priority>0.80</priority>';
$sitemap .= '</url>';
$cat_service1 = db_array('SELECT * FROM categories WHERE cat_type = "services" AND cat_parent_id = 0 ORDER BY cat_order');
foreach($cat_service1 as $cat1) {
   $sitemap .= '<url>';
   $sitemap .= '<loc>'.DOMAIN.url_services_cat($cat1['cat_alias']).'</loc>';
   $sitemap .= '<changefreq>Weekly</changefreq>';
   $sitemap .= '<priority>0.80</priority>';
   $sitemap .= '</url>';
   $cat_service2 = db_array('SELECT * FROM categories WHERE cat_type = "services" AND cat_parent_id = '.$cat1['cat_id'].' ORDER BY cat_order');
   foreach($cat_service2 as $cat2) {
      $sitemap .= '<url>';
      $sitemap .= '<loc>'.DOMAIN.url_services_cat($cat2['cat_alias']).'</loc>';
      $sitemap .= '<changefreq>Weekly</changefreq>';
      $sitemap .= '<priority>0.80</priority>';
      $sitemap .= '</url>';
   }
}  
         
// May tinh bang
$sitemap .= '<url>';
$sitemap .= '<loc>'.DOMAIN.'/may-tinh-bang/'.'</loc>';
$sitemap .= '<changefreq>Weekly</changefreq>';
$sitemap .= '<priority>0.80</priority>';
$sitemap .= '</url>';
$list_catpro = db_array('SELECT cat_name,cat_alias FROM categories WHERE cat_type = "products" LIMIT 20');
foreach($list_cat1 as $cat) {
   $sitemap .= '<url>';
   $sitemap .= '<loc>'.DOMAIN.'/may-tinh-bang-'.$cat['cat_alias'].'/'.'</loc>';
   $sitemap .= '<changefreq>Weekly</changefreq>';
   $sitemap .= '<priority>0.80</priority>';
   $sitemap .= '</url>';
}      

// Phu kien
$sitemap .= '<url>';
$sitemap .= '<loc>'.DOMAIN.'/phu-kien/'.'</loc>';
$sitemap .= '<changefreq>Weekly</changefreq>';
$sitemap .= '<priority>0.80</priority>';
$sitemap .= '</url>';
$list_cat1 = db_array('SELECT cat_name,cat_alias FROM categories WHERE cat_type = "accessories" LIMIT 15');
foreach($list_cat1 as $cat) {
   $sitemap .= '<url>';
   $sitemap .= '<loc>'.DOMAIN.'/phu-kien-'.$cat['cat_alias'].'/'.'</loc>';
   $sitemap .= '<changefreq>Weekly</changefreq>';
   $sitemap .= '<priority>0.80</priority>';
   $sitemap .= '</url>';
}
     
// KM
$sitemap .= '<url>';
$sitemap .= '<loc>'.DOMAIN.'/khuyen-mai/'.'</loc>';
$sitemap .= '<changefreq>Weekly</changefreq>';
$sitemap .= '<priority>0.40</priority>';
$sitemap .= '</url>';
              
// TT
$sitemap .= '<url>';
$sitemap .= '<loc>'.DOMAIN.'/tin-tuc/'.'</loc>';
$sitemap .= '<changefreq>Weekly</changefreq>';
$sitemap .= '<priority>0.60</priority>';
$sitemap .= '</url>';

//Cac dt
$list_products = db_array('SELECT pro_id,pro_name,pro_alias,pro_type
                              FROM products
                              WHERE pro_active = 1 AND pro_type = 1
                              ORDER BY pro_id DESC
                              LIMIT 60');
foreach($list_products as $product) {
   $sitemap .= '<url>';
   $sitemap .= '<loc>'.DOMAIN.url_product_detail($product).'</loc>';
   $sitemap .= '<changefreq>Weekly</changefreq>';
   $sitemap .= '<priority>0.50</priority>';
   $sitemap .= '</url>';
}

//Cac dich vu
$list_services = db_array('SELECT ser_alias
                           FROM services
                           WHERE ser_active = 1
                           ORDER BY ser_id DESC
                           LIMIT 60');
foreach($list_services as $service) {
   $sitemap .= '<url>';
   $sitemap .= '<loc>'.DOMAIN.url_services_detail($service).'</loc>';
   $sitemap .= '<changefreq>Weekly</changefreq>';
   $sitemap .= '<priority>0.50</priority>';
   $sitemap .= '</url>';
}

//Cac phu kien
$list_products = db_array('SELECT acc_alias
                           FROM accessories
                           WHERE acc_active = 1
                           ORDER BY acc_id DESC
                           LIMIT 40');
foreach($list_products as $product) {
   $sitemap .= '<url>';
   $sitemap .= '<loc>'.DOMAIN.url_accessories_detail($product).'</loc>';
   $sitemap .= '<changefreq>Weekly</changefreq>';
   $sitemap .= '<priority>0.50</priority>';
   $sitemap .= '</url>';
}

//các tt
$news_cat = db_array('SELECT * FROM news WHERE new_active = 1 ORDER BY new_id DESC LIMIT 20');
foreach($news_cat as $news) {
    $sitemap .= '<url>';
    $sitemap .= '<loc>'.DOMAIN.url_news_detail($news['new_alias']).'</loc>';
    $sitemap .= '<changefreq>Weekly</changefreq>';
    $sitemap .= '<priority>0.30</priority>';
    $sitemap .= '</url>';
}

//sitemap  
$sitemap .= '<url>';
$sitemap .= '<loc>'.DOMAIN.'/sitemap.xml'.'</loc>';
$sitemap .= '<changefreq>Daily</changefreq>';
$sitemap .= '<priority>0.80</priority>';
$sitemap .= '</url>';
ob_clean();
?>
<?header ("Content-Type:text/xml");?>
<?php 
echo '<?xml version="1.0" encoding="UTF-8"?>';
?>
<urlset
      xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9
            http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">
<?=$sitemap?>
</urlset>
